<template>
  <div class="warpper">
    <div class="toolbar" style="float: right;">
      <el-button type="primary" v-permission="['brands.store']" plain @click="add" style="margin:0 30px;">+New</el-button>
    </div>
    <div class="table">
      <el-table :data="tableData" size="small" stripe border style="width: 100%">

        <el-table-column prop="id" label="Id" width="50" align="center" />

        <el-table-column prop="name" label="Name" align="center" />

        <el-table-column label="Action" width="150" align="center">
          <template slot-scope="scope">
            <el-button plain v-permission="['brands.update']" @click="edit(scope.row.id)">Edit</el-button>
            <!-- <el-button plain type="danger" @click="del(scope.row.id)">del</el-button> -->
          </template>
        </el-table-column>

      </el-table>

    </div>

    <div class="page">
      <el-pagination background :current-page="page.current_page" :page-sizes="page.sizes" :page-size="page.per_page"
        layout="prev, pager, next" :total="page.total" @size-change="sizeChange" @current-change="currentChange" />
    </div>


    <el-dialog :title="title" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="70%">
      <el-form v-if="dialogFormVisible" ref="ruleForm" :model="formData" :rules="rules" label-width="140px">

        <el-form-item label="name" prop="name">
          <el-input v-model="formData.name" style="width: 400px" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">cancel</el-button>
        <el-button type="primary" @click="saveData()">Save</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import CURD from "@/mixin/CURD";
  import {
    update
  } from "@/api/brand";
  export default {
    name: "brandIndex",
    components: {},
    mixins: [CURD],
    data() {
      return {
        module: "brand",
        newTitle: "New Brand",
        editTitle: "Edit Brand",
        dialogFormVisible: false,
        id: "",
        formData: {},
        isShow: false,
      };
    },
    async created() {

    },

    methods: {
      uploadData() {
        this.isShow = true;
      },
      async edit(id) {
        const {
          show
        } = require(`@/api/${this.module}`);
        const {
          data
        } = await show(id);
        let result = data;
        this.formData = result;
        this.isNew = false;
        this.isEdit = true;
        this.setTitle();
        this.dialogFormVisible = true;
      },
      saveData() {
        this.save("ruleForm");
      }
    }
  };
</script>

<style>
  .table,
  .toolbar,
  .page {
    margin: 20px;
  }

  .toolbar {
    margin-top: 10px;
    ;
    padding: 5px;
  }

  .table {
    margin-bottom: 10px;
  }

  .page {
    margin-top: 10px;
  }

  .page {
    text-align: center;
  }

  .el-form table tbody {
    width: 100%;
  }

  .el-form .header {
    box-sizing: border-box;
    border: 1px solid #ccc;
    background-color: #09f;
    color: #fff;
    height: 44px;
    display: flex;
    flex-direction: row;
  }

  .el-form .header .title {
    margin: auto;
    font-weight: bold;
  }

  .el-form .content {
    display: flex;
    box-sizing: border-box;
    border: 1px solid #ccc;
    background-color: #0cf;
    color: #fff;
    height: 44px;
    flex-direction: row;
  }

  .el-form .content div {
    margin: auto;
    border-radius: 0px;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>